package com.sunxueqi.project.log.service.impl;

import java.sql.Timestamp;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sunxueqi.common.constant.StatusConstants;
import com.sunxueqi.common.utils.SecurityUtils;
import com.sunxueqi.project.log.dao.LoginLogMapper;
import com.sunxueqi.project.log.service.ILoginLogService;
import com.sunxueqi.project.log.vo.LoginLog;

@Service
public class LoginLogServiceImpl implements ILoginLogService{

	@Autowired
	private LoginLogMapper loginLogMapper;
	
	@Override
	public List<LoginLog> selectLoginLogList(LoginLog loginLog) {
		loginLog.setDeleteStatus(StatusConstants.NORMAL);
		return loginLogMapper.selectList(loginLog);
	}

	@Override
	public int deleteLoginLogByIds(String[] idArray) {
		int result = 0;
		for(String id: idArray) {
			LoginLog loginLog = new LoginLog();
			loginLog.setId(id);
			loginLog.setDeleteStatus(StatusConstants.DELETED);
			loginLog.setDeleteTime(new Timestamp(System.currentTimeMillis()));
			loginLog.setDeleteBy(SecurityUtils.getLoginUserId());
			int count = loginLogMapper.updateByPrimaryKey(loginLog);
			result += count;
		}
		return result;
	}
	
	@Override
	public int cleanLog() {
		return loginLogMapper.cleanLog(SecurityUtils.getLoginUserId(), StatusConstants.DELETED, StatusConstants.NORMAL);
	}

	@Override
	public void addLog(LoginLog loginLog) {
		loginLogMapper.insert(loginLog);
	}


}
